/**
 * Copyright (c) 2012 Nokia Corporation.
 * All rights reserved.
 *
 * For the applicable distribution terms see the license text file included in
 * the distribution.
 */

import QtQuick 1.1
import com.nokia.meego 1.0

Page {
    id: loginPage
    property string token: ""

    LoginView {
        id: loginView
        anchors.fill: parent
        onLoginCompleted: pageStack.pop();
        onWebViewLoadFailed: failedToLoadDialog.open();
    }

    Column {
        width: childrenRect.width
        height: childrenRect.height
        anchors.centerIn: parent
        opacity: (loginView.webViewProgress < 1) ? 1 : 0;
        spacing: 20
        Behavior on opacity { NumberAnimation { duration: 400 } }

        Label {
            id: label
            color: "black"
            text: "Loading..."
                  + Math.round(loginView.webViewProgress * 100) + " %";
        }
        BusyIndicator {
            id: busyIndicator
            x: label.width > width ? (label.width - width) / 2 : 0; // Center
            platformStyle: BusyIndicatorStyle { size: "large" }
            running: true
        }
    }

    // A dialog to be shown in case the login view fails to load the content
    QueryDialog {
        id: failedToLoadDialog
        titleText: qsTr("Error");
        message: qsTr("Failed to load the login page.");
        acceptButtonText: qsTr("Retry");
        rejectButtonText: qsTr("Abort");
        onAccepted: loginView.reload.trigger();
    }

    tools: ToolBarLayout {
        // This is just a placeholder and always disabled since we don't use
        // the back button for exiting in Harmattan.
        ToolIcon {
            iconId: "toolbar-back"
            enabled: false
            opacity: 0.3
        }
        ToolIcon {
            iconId: "toolbar-refresh"
            enabled: loginView.reload.enabled
            opacity: enabled ? 1.0 : 0.3;
            onClicked: loginView.reload.trigger();
        }
    }
}
